import { mongo } from "../mogoConfig"

const run = async () => {
    const tb = mongo.db("my_test").collection("inde_test")

    const result1 = await tb.createIndex({ name: 1 },
        { name: "name_idx1" })
    console.log("创建索引1--------------------------------")
    console.log(JSON.stringify(result1))


    const result2 = await tb.createIndex({ content: "text", "users.comments": "text", "users.profiles": "text" },
        { name: "name_idx2" })
    console.log("创建索引2--------------------------------")
    console.log(JSON.stringify(result2))



    const indexs = await tb.indexes()
    console.log("所有索引---------------------------------")
    for (const index of indexs) {
        console.log(JSON.stringify(index))
    }

    console.log("删除所有索引")
    const result = await tb.dropIndexes()
    console.log(JSON.stringify(result))

}


run()
    .catch(error => {
        console.log(error)
    })
    .finally(() => {
        mongo.close()
        console.log("执行完成")
    })